package com.cmos.service.impl;

import com.cmos.dao.PrivilegeDao;
import com.cmos.entity.Privilege;
import com.cmos.service.PrivilegeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class PrivilegeServiceImpl implements PrivilegeService {
    //注入PrivilegeDao
    @Resource
    private PrivilegeDao privilegeDao;

    //添加权限
    @Override
    public int savePrivilege(Privilege privilege) {
        return privilegeDao.insert(privilege);
    }

    //删除权限
    @Override
    public int removePrivilege(String id) {
        return privilegeDao.deleteByPrimaryKey(id);
    }

    //修改权限信息
    @Override
    public int changePrivilege(Privilege privilege) {
        return privilegeDao.updateByPrimaryKeySelective(privilege);
    }

    //查询权限信息
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Privilege queryPrivilege(Privilege privilege) {
        return privilegeDao.selectOne(privilege);
    }

    //查询所有权限
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Privilege> queryAllPrivilege() {
        return privilegeDao.selectAll();
    }
}
